package com.styytech.dadabao.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.styytech.dadabao.R;
import com.styytech.dadabao.bean.SaleRecord;
import com.styytech.dadabao.bean.TransactionDetails;
import com.styytech.dadabao.bean.UserRecord;

import java.util.LinkedList;

/**
 * Created by user on 2015/8/14.
 */
public class SaleRecordItemAdapter extends BaseAdapter {

    private LinkedList<Object> mList = null;
    private LayoutInflater mInflater = null;
    ViewHolder holder = null;
    private Context mContext;

    public SaleRecordItemAdapter(LinkedList<Object> mList, Context context) {
        // TODO Auto-generated constructor stub
        this.mList = mList;
        this.mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup arg2) {
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(
                    R.layout.item_sale_record, null);
            holder.tv_user_name = (TextView) convertView.findViewById(R.id.tv_user_name);
            holder.tv_investment_amount = (TextView) convertView.findViewById(R.id.tv_investment_amount);
            holder.tv_investment_time = (TextView) convertView.findViewById(R.id.tv_investment_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
       Object obj= mList.get(position);
        if (obj instanceof SaleRecord){
            Log.e("sadsa","SaleRecord-----"+position);
            SaleRecord itemData = (SaleRecord) obj;
            holder.tv_user_name.setText(itemData.getUserName());
            holder.tv_investment_amount.setText(itemData.getInvestmentAmount() + "元");
            holder.tv_investment_time.setText(itemData.getInvestmentTime());
        }
        if (obj instanceof UserRecord){
            Log.e("sadsa","UserRecord-----"+position);
            UserRecord itemData = (UserRecord) obj;
            holder.tv_user_name.setText(itemData.getProductName());
            holder.tv_investment_amount.setText(itemData.getMoney()+"元");
            holder.tv_investment_time.setText(itemData.getStatus());
        }
        if (obj instanceof TransactionDetails){
            Log.e("sadsa","UserRecord-----"+position);
            TransactionDetails itemData = (TransactionDetails) obj;
            holder.tv_user_name.setText(itemData.getFund_behavior());
            holder.tv_investment_amount.setText(itemData.getOperating_amount()+"元");
            holder.tv_investment_time.setText(itemData.getTime());
        }




        return convertView;
    }

    private class ViewHolder {
        //项目姓名
        private TextView tv_user_name;
        //项目金额
        private TextView tv_investment_amount;
        //项目时间
        private TextView tv_investment_time;


    }
}
